const wordPool = [
  { english: 'Apple', chinese: '苹果', image: '/images/words/apple.png' },
  { english: 'Banana', chinese: '香蕉', image: '/images/words/banana.png' },
  { english: 'Cat', chinese: '猫', image: '/images/words/cat.png' },
  { english: 'Dog', chinese: '狗', image: '/images/words/dog.png' },
  { english: 'Sun', chinese: '太阳', image: '/images/words/sun.png' }
];

// 微信小程序内置音频播放器
const innerAudioContext = wx.createInnerAudioContext();

Page({
  data: {
    currentWord: {},
    currentIndex: 0
  },

  onLoad(options) {
    this.loadWord(0);
  },

  loadWord(index) {
    this.setData({
      currentWord: wordPool[index],
      currentIndex: index
    });
  },

  playAudio() {
    // 模拟播放音频，实际应替换为真实的音频文件路径
    // 例如：innerAudioContext.src = `https://your.audio.server/${this.data.currentWord.english}.mp3`;
    // innerAudioContext.play();
    wx.showToast({
      title: `正在播放 ${this.data.currentWord.english} 的发音`,
      icon: 'none'
    });
  },

  prevWord() {
    let prevIndex = this.data.currentIndex - 1;
    if (prevIndex < 0) {
      prevIndex = wordPool.length - 1; // 循环到最后一个
    }
    this.loadWord(prevIndex);
  },

  nextWord() {
    let nextIndex = this.data.currentIndex + 1;
    if (nextIndex >= wordPool.length) {
      nextIndex = 0; // 循环到第一个
    }
    this.loadWord(nextIndex);
  }
});
